package cn.hrlly.tao2shou.biz;

import android.content.Context;

import java.util.ArrayList;

import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.domain.CommodityList;
import cn.hrlly.tao2shou.domain.HistorySearch;
import cn.hrlly.tao2shou.listener.OnSearchCommoditiesListener;
import cn.hrlly.tao2shou.utils.CacheUtil;
import cn.hrlly.tao2shou.utils.DatabaseUtil;

/**
 * User: gengliang
 * Date: 2016-01-29
 * Time: 10:15
 */

public class SearchCommoditiesBizImpl implements SearchCommoditiesBiz {

    private OnSearchCommoditiesListener onSearchCommoditiesListener;
    private DatabaseUtil databaseUtil;

    public SearchCommoditiesBizImpl(OnSearchCommoditiesListener onSearchCommoditiesListener,Context context){
        this.onSearchCommoditiesListener=onSearchCommoditiesListener;
        this.databaseUtil=new DatabaseUtil(context);
    }

    @Override
    public void showHistory() {
        ArrayList<String> searchList=new ArrayList<String>();
        searchList= (ArrayList<String>) databaseUtil.selectHistorySearch();
        if(searchList!=null)
            onSearchCommoditiesListener.showHistoryCommoditiesSucc(searchList);
    }

    @Override
    public void clearHistory() {
        databaseUtil.deleteHistorySearch();
    }

    @Override
    public void saveHistory(String antistop) {
        HistorySearch search=new HistorySearch();
        search.setSearchName(antistop);
        databaseUtil.insertHistorySearch(search);
    }

    @Override
    public void closeDataBase() {
        databaseUtil.closeDatabase();
    }
}
